var l = location.href;
if (l.indexOf("&j=") != -1) {
    var js = l.substring(l.indexOf("&j="), l.indexOf("#kan")).split("=")[1];
    $("#mad" + js).css({"background": "#517FAF", "border": "1px solid #517FAF", "color": "#fff"});
} else if (l.indexOf("&j1=") != -1) {
    var js = l.substring(l.indexOf("&j1="), l.indexOf("#kan")).split("=")[1];
    $("#flh" + js).css({"background": "#517FAF", "border": "1px solid #517FAF", "color": "#fff"});
}


/*在线播放*/
function Mad(e) {
    var f = $(e).attr("data");
    var j = $(e).attr("j");
    if (f != "") {
        location.href = window.prourl+"/index/xl/detail/film_id/"+window.filmId+"/src/" + f + "/j/" + j + "#kan";
    }
}

function Flh(e) {
    var f = $(e).attr("data");
    var j = $(e).attr("j");
    if (f != "") {
        location.href = window.prourl+"/index/xl/detail/film_id/"+window.filmId+"/src1/" + f + "/j1/" + j + "#kan";
    }
}
/*在线播放*/


$('#star').raty({
    hints: ['很烂', '很烂', '一般', '一般', '不妨一看', '不妨一看', '比较精彩', '比较精彩', '棒极了', '棒极了'],
    number: 10,
    path: "public/static/img/star",
    size: 24,
    starOff: 'star-off-big.png',
    starOn: 'star-on-big.png',
    precision: true,
    score: function () {
        return $(this).attr('data-score');
    },
    click: function (score, evt) {

        /*获取是否存在cookie评分值*/
        if (getCookie("raty{$film.id}") == null) {
            /**
             * 未评分
             */
            saveRaty("{$film.id}", score);
        } else {
            alert("你已经评过分了，你的评分" + getCookie("raty${film.id}") + "分");
            location.reload();
        }

    }
});

function saveRaty(film_id, score) {
    $.ajax({
        url: "{:url('xl/addRaty')}",
        type: "post",
        dataType: "json",
        data: "film_id=" + film_id + "&score=" + score,
        success: function (data) {
            debugger;
            if (JSON.parse(data).code == '1') {
                alert("评分成功,你的评分" + score + "分");
                setCookie("raty${film.id}", score);
            } else {
                alert("评分失败,请稍后重试！");
            }
            location.reload();
        }
    });
}

/*失效一键反馈*/
function fk(e) {
    /*获取是否存在cookie评分值*/
    if (getCookie(e+"${film.id}") == null) {
        /**
         * 未评分
         */
        var title = "";
        var content = "";
        switch (e) {
            case "y1":
                title = "在线点播1失效反馈";
                content = "胖哥温馨提示：你好，有一位本网站忠实粉丝惊奇的发现${film.cataLogName}-${film.subClassName}-${film.typeName}-<span  style='color:#00AFE4;'>[${film.name}]</span>的在线点播1已失效，请前往<a href='${prourl}xl/detail.html?film_id=${film.id}'>查看</a>是否失效，若失效请去<a href='${prourl}film.html?film_id=${film.id}'>更改</a>";
                break;
            case "y2":
                title = "在线点播2失效反馈";
                content = "胖哥温馨提示：你好，有一位本网站忠实粉丝惊奇的发现${film.cataLogName}-${film.subClassName}-${film.typeName}-<span  style='color:#00AFE4;'>[${film.name}]</span>的在线点播2已失效，请前往<a href='${prourl}xl/detail.html?film_id=${film.id}'>查看</a>是否失效，若失效请去<a href='${prourl}film.html?film_id=${film.id}'>更改</a>";
                break;
            case "x1":
                title = "下载地址1失效反馈";
                content = "胖哥温馨提示：你好，有一位本网站忠实粉丝惊奇的发现${film.cataLogName}-${film.subClassName}-${film.typeName}-<span  style='color:#00AFE4;'>[${film.name}]</span>的下载地址1已失效，请前往<a href='${prourl}xl/detail.html?film_id=${film.id}'>查看</a>是否失效，若失效请去<a href='${prourl}film.html?film_id=${film.id}'>更改</a>";
                break;
            case "x2":
                title = "下载地址2失效反馈";
                content = "胖哥温馨提示：你好，有一位本网站忠实粉丝惊奇的发现${film.cataLogName}-${film.subClassName}-${film.typeName}-<span  style='color:#00AFE4;>[${film.name}]</span>的下载地址2已失效，请前往<a href='${prourl}xl/detail.html?film_id=${film.id}'>查看</a>是否失效，若失效请去<a href='${prourl}film.html?film_id=${film.id}'>更改</a>";
                break;
            default:
                alert("参数错误");
                break;
        }
        if(title!=""&&content!=""){
            $.ajax({
                url: "sendEmail.html",
                type: "post",
                dataType: "json",
                data: "title=" + title + "&content=" + content,
                success: function (data) {
                    if (JSON.parse(data).code == '1') {
                        alert("反馈成功，我们会尽快处理");
                        setCookie(e+"${film.id}", e);
                    } else {
                        alert("反馈失败,请稍后重试！");
                    }
                }
            });
        }
    } else {
        alert("你已经反馈过了，谢谢你的支持");
    }
}

/*对cookie的操作*/
var username = document.cookie.split(";")[0].split("=")[1];
//JS操作cookies方法!
//写cookies
function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

/*读取cookies*/
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

/*删除cookie*/
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
//使用示例
/*    setCookie("name","hayden");
 alert(getCookie("name"));
 //如果需要设定自定义过期时间
 //那么把上面的setCookie　函数换成下面两个函数就ok;
 //程序代码
 function setCookie(name,value,time)
 {
 var strsec = getsec(time);
 var exp = new Date();
 exp.setTime(exp.getTime() + strsec*1);
 document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
 }
 function getsec(str)
 {
 alert(str);
 var str1=str.substring(1,str.length)*1;
 var str2=str.substring(0,1);
 if (str2=="s")
 {
 return str1*1000;
 }
 else if (str2=="h")
 {
 return str1*60*60*1000;
 }
 else if (str2=="d")
 {
 return str1*24*60*60*1000;
 }
 }
 //这是有设定过期时间的使用示例：
 //s20是代表20秒
 //h是指小时，如12小时则是：h12
 //d是天数，30天则：d30
 setCookie("name","hayden","s20");*/